load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//staging/src/kubevirt.io/client-go/version:def.bzl", "version_x_defs")

go_library(
    name = "go_default_library",
    srcs = ["virt-exportproxy.go"],
    importpath = "kubevirt.io/kubevirt/cmd/virt-exportproxy",
    visibility = ["//visibility:private"],
    deps = [
        "//pkg/certificates/bootstrap:go_default_library",
        "//pkg/controller:go_default_library",
        "//pkg/service:go_default_library",
        "//pkg/util/tls:go_default_library",
        "//staging/src/kubevirt.io/api/export/v1beta1:go_default_library",
        "//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
        "//staging/src/kubevirt.io/client-go/log:go_default_library",
        "//staging/src/kubevirt.io/client-go/util:go_default_library",
        "//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
        "//vendor/k8s.io/client-go/tools/cache:go_default_library",
        "//vendor/k8s.io/client-go/util/certificate:go_default_library",
        "//vendor/k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset:go_default_library",
    ],
)

go_binary(
    name = "virt-exportproxy",
    embed = [":go_default_library"],
    static = "on",
    visibility = ["//visibility:public"],
    x_defs = version_x_defs(),
)

pkg_tar(
    name = "get-version",
    srcs = ["//:get-version"],
    package_dir = "/",
)

pkg_tar(
    name = "virt-exportproxy-bin",
    srcs = [":virt-exportproxy"],
    package_dir = "/usr/bin",
)

oci_image(
    name = "version-container",
    base = "//:passwd-image",
    tars = [
        ":get-version",
    ],
)

oci_image(
    name = "virt-exportproxy-image",
    base = ":version-container",
    entrypoint = ["/usr/bin/virt-exportproxy"],
    tars = [
        ":virt-exportproxy-bin",
    ],
    user = "1001",
    visibility = ["//visibility:public"],
)
